package util;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sun.misc.BASE64Encoder;

import java.io.*;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

public class controller {
// window.location.href="<%=path%>/exportSellPlan?id=" + id;
    /*@RequestMapping("/exportSellPlan")
    public @ResponseBody
    void exportSellPlan(Long id){
        Calendar calendar = Calendar.getInstance();// 取当前日期。
        if(id!=null){
            SellPlan plan=sellService.getSellPlanInfo(id);//数据
            //获得数据
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("bYear", plan.getBusinessYear()!=null?plan.getBusinessYear():"");
            map.put("lYear", plan.getLiveYear()!=null?plan.getLiveYear():"");
            map.put("leader",plan.getLeader()!=null?plan.getLeader():"");
            map.put("phone", plan.getPhone()!=null?plan.getPhone():"");
            map.put("curYear", calendar.get(Calendar.YEAR)+"");
            map.put("image", getImageBase(plan.getPositionImage()));
            try {
                WordUtils.exportMillCertificateWord(getRequest(),getResponse(),map,"方案","sellPlan.ftl");
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    //获得图片的base64码
    @SuppressWarnings("deprecation")
    public String getImageBase(String src) {
        if(src==null||src==""){
            return "";
        }
        File file = new File(getRequest().getRealPath("/")+src.replace(getRequest().getContextPath(), ""));
        if(!file.exists()) {
            return "";
        }
        InputStream in = null;
        byte[] data = null;
        try {
            in = new FileInputStream(file);
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        }
        try {
            data = new byte[in.available()];
            in.read(data);
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        BASE64Encoder encoder = new BASE64Encoder();
        return encoder.encode(data);
    }
}*/}
